/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package utilities;


import java.text.ParseException;
import java.text.SimpleDateFormat;

import java.util.Date;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author VietLH
 */
public class SimpleDateFormatter {

    private String fDate;

    public SimpleDateFormatter() {
    }

    public String convertDateToString(Date date) {
        SimpleDateFormat formatter = new SimpleDateFormat("MM/dd/yyyy");
        fDate=formatter.format(date); //using the date object from earlier
        return fDate;
    }

    public Date convertStringToDate(String date) {
        try {
            SimpleDateFormat formatter = new SimpleDateFormat("MM/dd/yyyy"); //please notice the capital M
            Date dateObj = formatter.parse(date);
            return dateObj;
        } catch (ParseException ex) {
            Logger.getLogger(SimpleDateFormatter.class.getName()).log(Level.SEVERE, null, ex);
        }
        return null;
    }

     public int getDay(Date date){
        SimpleDateFormat formatter = new SimpleDateFormat("MM/dd/yyyy");
        String datePattern=formatter.format(date);
        String day=(String) (datePattern).substring(3, 5);
        return Integer.parseInt(day)-1;
    }
    public int getMonth(Date date){
        SimpleDateFormat formatter = new SimpleDateFormat("MM/dd/yyyy");
        String month=(String) (formatter.format(date)).substring(0, 2);
        return Integer.parseInt(month)-1;
    }
    public int getYear(Date date){
        SimpleDateFormat formatter = new SimpleDateFormat("MM/dd/yyyy");
        String year=(String) (formatter.format(date)).substring(6);
        return Integer.parseInt(year)-1900;
    }

}
